<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Project_model extends CI_Model {

    public $tablename = 'hpg_project';
    
    public $tab_roadshow = 'hpg_project_roadshow';
    
    public function gePageList($type=0, $page=1, $limit=20){
        $start = ($page-1)*$limit;
        $query = $this->db;
        if( $type ){
            $query->where('is_start', 1);
        }
        $count = $query->count_all_results($this->tablename, false);
        $list = $query->select('id,project_name,company_desc,company_area,project_mark,company_legal,
            finance_rotation,finance_expect,project_cover,project_team,manager')->limit($limit, $start)->order_by('id', 'desc')->get_array();
        return [intval($count), $list ? $list : []];
    }
    
    public function getProjectOne($id, $fields='*'){
        if( !$id ){
            return false;
        }
        $data = $this->db->from($this->tablename)->select($fields)->where('id', $id)->fetchOne();
        return $data;
    }
    
    public function getRoadShow($project_id){
        if( !$project_id ){
            return false;
        }
        $data = $this->db->from($this->tab_roadshow)->where('project_id', $project_id)->fetchOne();
        return $data ? $data : [];
    }
}
?>